<!--
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 14:41:20
 * @LastEditTime: 2023-04-30 13:25:01
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description:   :gridOps="gridOptions" 
-->
<template>
  <sc-VxeTable
    ref="xGrid1"
    :gridEvts="gridEvents"
    :tablecode="'fiance_invoice_creditor'"
    :url="this.$API.finance.invoice.details"
    :params="{ state_id: 1 }"
  >
  </sc-VxeTable>

  <save-dialog
    v-if="dialog.save"
    ref="saveDialog"
    @success="handleSuccess"
    @closed="dialog.save = false"
  >
  </save-dialog>

  <invoicestate
    v-if="dialog.invoicestate"
    ref="invoicestateDialog"
    @success="handleSuccess"
    @closed="dialog.invoicestate = false"
  >
  </invoicestate>
</template>
<script>
// import { useRouter } from "vue-router";
// import { VXETable } from 'vxe-table';
import { ElNotification } from "element-plus";
import SaveDialog from "./csave";
import invoicestate from "./invoicestate";

export default {
  components: {
    invoicestate,
    SaveDialog,
  },
  name: "fiance_invoice_creditor",
  data() {
    return {
      dialog: {
        save: false,
        invoicestate: false,
      },
      gridEvents: {
        cellDblclick: ({ row }) => {
          this.edit(row);
        },
        add: () => {
          this.openSave();
        },
        edit: ({ button }) => {
          this.edit(button.selectRecords[0]);
        },
        del: () => {
          this.del();
        },
        invoice_status: ({ button }) => {
          this.invoice_status(button.selectRecords.map((v) => v.id));
        },
      },
    };
  },
  methods: {
    openSave: function () {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open();
      });
    },
    handleSuccess() {
      this.$refs.xGrid1.refresh();
    },
    edit(item) {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open("edit").setData(item);
      });
    },
    invoice_status: function (ids) {
      this.dialog.invoicestate = true;
      this.$nextTick(() => {
        this.$refs.invoicestateDialog.open("edit").setData({ ids: ids });
      });
    },
    async del() {
      let selected = this.$refs.xGrid1.xGrid.getCheckboxRecords();
      if (selected.length == 0) {
        ElNotification.error({
          title: "错误",
          message: "必须选中元素",
        });
        return;
      }
      let ids = [];
      selected.forEach((element) => {
        ids.push(element.id);
      });
      var res = await this.$API.basedata.material.delete.post({
        ids: ids,
      });
      this.isSaveing = false;
      if (res.code == 200) {
        this.$emit("success", this.form, this.mode);
        this.visible = false;
        this.$refs.xGrid1.refresh();
        this.$message.success("操作成功");
      } else {
        this.$alert(res.message, "提示", { type: "error" });
      }
    },
  },
};
</script>
